package com.linkoog.devtools.intellij.ui.table.column_info.provider.setter;

import com.linkoog.devtools.intellij.ui.table.TableRowData;
import com.linkoog.devtools.intellij.ui.table.column_info.provider.TableCellValueSetterProvider;

import java.lang.reflect.Field;

public class FieldTableCellValueSetterProvider<T extends TableRowData> implements TableCellValueSetterProvider<T> {

    private final String fieldName;

    public FieldTableCellValueSetterProvider(String fieldName) {
        this.fieldName = fieldName;
    }

    @Override
    public void setValue(T itemInfo, Object value) {
        try {
            Field declaredField = itemInfo.getClass().getDeclaredField(fieldName);
            declaredField.setAccessible(true);
            declaredField.set(itemInfo, value);
        } catch (Exception ignored) {
        }
    }
}
